import pymysql
import time
class MySQLDB:
    """
    为了保障用户数据安全，数据库没有任何上传信息操作
    """
    @staticmethod
    def get_one_data(y1, m, d,h):
        """
        获取具体一天的时间信息
        :param y1:年
        :param m:月
        :param d:日
        :return:
        """
        connection = pymysql.connect(host='rm-bp1zq3879r28p726lco.mysql.rds.aliyuncs.com',
                                     user='qwe8403000',
                                     password='****',
                                     db='arm_calendar')
        try:
            with connection.cursor() as cursor:
                sql = "SELECT * FROM year_info where year='%s' and month='%s' and day='%s' and SUBSTR(d_solar,12,2) = '%s'" % (
                    y1, int(m), int(d),h)
                print(sql)
                cursor.execute(sql)
                return cursor.fetchall()
        except pymysql.MySQLError as e:
            print(f"错误：{e}")
        finally:
            connection.close()
            
    @staticmethod
    def get_info_s(r, now_hour):
            info_s = "天干地支：%s%s%s%s,属相：%s,阴历时间：%s,具体时辰：%s,六壬月：%s,六壬天：%s,六壬日：%s," \
                     "月相：%s,物候：%s,节气：%s,三元九运：%s,日禄：%s,六爻：%s,七曜：%s,彭祖天干：%s,彭祖地支：%s,八字：%s," \
                     "纳音：%s,日宜：%s,日忌：%s,时宜：%s,时忌：%s,吉神：%s,凶神：%s,每日相冲生肖：%s,每日相冲方位：%s," \
                     "星宿：%s,星宿吉凶：%s,星宿歌曲：%s,阳贵神方位：%s,阴贵神方位：%s,喜神方位：%s,福神方位：%s,财神方位：%s," \
                     "月胎神：%s,今日胎神：%s,太岁方向：%s,十二值星：%s日,北斗九星-年份-九数：%s,北斗九星-年份-七色：%s,北斗九星-年份-五行属性：%s," \
                     "方位：%s,北斗九星：%s,北斗九星名称：%s,北斗九星-吉凶：%s,北斗九星-奇门：%s,北斗九星-八门：%s,北斗九星-八门吉凶：%s," \
                     "北斗九星-八门-奇门阴阳：%s,北斗九星-太乙名称：%s,北斗九星-太乙类型：%s,北斗九星-太乙九神歌诀：%s,北斗九星详解：%s" \
                     % \
                     (r[2], r[3], r[4], r[5], r[1], r[22], now_hour, r[18], r[19], r[20], r[31], r[32], r[33], r[37],
                      r[38], r[39], r[40], r[41], r[42], r[43], r[44], r[45], r[46], r[47], r[48], r[49], r[50], r[54],
                      r[55], r[58], r[59], r[60], r[62], r[64], r[66], r[68], r[70], r[71], r[72], r[78], r[79], r[80],
                      r[81], r[82], r[84], r[85], r[86], r[87], r[88], r[89], r[90], r[91], r[92], r[93], r[94], r[96]
                      )
            info_s = info_s.replace(" ", "").replace("\n", "").replace("，", ",").replace("。", ".").replace("：", ":")
            return info_s
    @staticmethod
    def get_mysql_msg():
        try:
            now_time = time.localtime()
            # 年月日拆分并传入参数
            y1 = now_time.tm_year
            m = now_time.tm_mon
            d = now_time.tm_mday
            # 时分秒
            h = now_time.tm_hour
            # h如果小于10，前面补0
            if h < 10:
                h = "0" + str(h)
            dataSet = MySQLDB.get_one_data(y1,m,d,h)
            return MySQLDB.get_info_s(dataSet[0],h)
        except Exception as e:
            print(f"错误：{e}")

# 使用示例
if __name__ == '__main__':
    print(MySQLDB.get_mysql_msg())